<script setup>
import { ref, reactive, toRaw } from 'vue'
import { service } from '@utils'
import store from '@store'

const user = store.getters.user
const isPlatform = !user.enterpriseType

const formRef = ref()
const formPlatRef = ref()
const requested = ref(false)

const state = reactive({
    param: {},
    number: {}
})

const rules = {
    workTime: [{ required: true, message: '请输入', trigger: 'blur' }],
    startTime: [{ required: true, message: '请输入', trigger: 'blur' }],
    outTimeNum: [{ required: true, message: '请输入', trigger: 'blur' }],
    outTimeNumMax: [{ required: true, message: '请输入', trigger: 'blur' }],
    backAddress: [{ required: true, message: '请输入', trigger: 'blur' }],
    rentRule: [{ required: true, message: '请输入', trigger: 'blur' }],
    compensateRule: [{ required: true, message: '请输入', trigger: 'blur' }]
}

const getData = async () => {
    requested.value = false
    const res = await service.bfqz.platformDetail()
    requested.value = true
    if (res) {
        state.param = { ...res }
    }
}

const getPlatData = async () => {
    // const res = await service.auth.companyRates('',true,0)
    // data.value = res

    let queryForm = {
        really:0
    }
    let data = await service.auth.companysByreally()
    
    if(data) {
        state.number.probeRisk = data.probeRisk
        state.number.seeRisk = data.seeRisk
        state.number.radarRisk = data.radarRisk
        state.number.companyCode = data.companyCode
        state.number.companyId = data.companyId
        // state.number.label = res.label
        
    }
}

const realPlatSubmit = async () => {
    // state.number.includePlatform = true
    // state.number.really = 0

    let res
        res = await service.auth.platformEditPlatformrisk(state.number)
    if (res) {
        ElMessage.success('修改成功')
        close()
        emit('refresh')
    }
}

const platSure = async () => {
    formPlatRef.value.validate((valid) => {
        if (valid) {
            realPlatSubmit()
        }
    })
}

const sure = async () => {
    formRef.value.validate((valid) => {
        if (valid) {
            realSubmit()
        }
    })
}

const realSubmit = async () => {
    const res = await service.bfqz.platformEdit(toRaw(state.param))
    if (res) {
        ElMessage.success('修改成功')
        getData()
    }
}

getData()
getPlatData()
</script>
    
<template>
    <section class="main-white">
        <el-skeleton v-if="!requested" :rows="6" animated />
        <section v-else class="flex-align-center paddingT25">
            <el-form :model="state.param" :rules="rules" style="width: 82%" label-width="125px" ref="formRef" label-suffix=":"
                onsubmit="return false;">
                <el-row :gutter="16">
                    <el-col :span="8" v-if="isPlatform">
                        <el-form-item label="客服工作时间" prop="workTime">
                            <el-input v-model="state.param.workTime" placeholder="请输入客服工作时间" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" v-if="isPlatform">
                        <el-form-item label="客服联系方式" prop="telPhone">
                            <el-input v-model="state.param.telPhone" placeholder="请输入客服联系方式" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="8" v-if="!isPlatform">
                        <el-form-item label="起租日开始时间" prop="startTime">
                            <el-input v-model="state.param.startTime" placeholder="请输入起租日开始时间" clearable></el-input>
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="8" v-if="!isPlatform">
                        <el-form-item label="逾期费用比例" prop="outTimeNum">
                            <el-input v-model="state.param.outTimeNum" type="number" :precision="4" placeholder="请输入逾期费用比例" clearable>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="8" v-if="!isPlatform">
                        <el-form-item label="最大逾期比例" prop="outTimeNumMax">
                            <el-input v-model="state.param.outTimeNumMax" type="number" :precision="4" placeholder="请输入最大逾期比例" clearable>
                            </el-input>
                        </el-form-item>
                    </el-col> -->
                    <!-- <el-col :span="8" v-if="isPlatform">
                        <el-form-item label="活动宣传标题" prop="title">
                            <el-input v-model="state.param.title" placeholder="请输入活动宣传标题" clearable></el-input>
                        </el-form-item>
                    </el-col> -->
                    <el-col v-if="!isPlatform">
                        <el-form-item label="归还地址" prop="backAddress">
                            <el-input v-model="state.param.backAddress" type="textarea" :rows="3" :maxlength="50" show-word-limit
                                placeholder="请输入归还地址" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col v-if="isPlatform">
                        <el-form-item label="租赁规则" prop="rentRule">
                            <el-input v-model="state.param.rentRule" type="textarea" :rows="3" :maxlength="200" show-word-limit
                                placeholder="请输入租赁规则" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col v-if="isPlatform">
                        <el-form-item label="赔偿规则" prop="compensateRule">
                            <el-input v-model="state.param.compensateRule" type="textarea" :rows="3" :maxlength="350" show-word-limit
                                placeholder="请输入赔偿规则" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col v-if="isPlatform">
                        <el-form-item label="显示图片" prop="picture">
                            <upload v-model="state.param.detailNotice" />
                        </el-form-item>
                    </el-col> -->
                </el-row>
            </el-form>
        </section>
        <section v-if="requested" class="flex-align-center">
            <el-button type="primary" @click="sure">保存</el-button>
        </section>

        <section class="flex-align-center paddingT25" v-if="isPlatform">
            <el-form :model="state.number" :rules="rules" style="width: 82%" label-width="125px" ref="formPlatRef" label-suffix=":"
                onsubmit="return false;">
                <el-row :gutter="16">
                    <el-col :span="8" >
                        <el-form-item label="视成报告" prop="seeRisk">
                            <el-input v-model="state.number.seeRisk" type="number" :precision="4" placeholder="请输入视成报告" clearable>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" >
                        <el-form-item label="全景雷达" prop="radarRisk">
                            <el-input v-model="state.number.radarRisk" type="number" :precision="4" placeholder="请输入全景雷达" clearable>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" >
                        <el-form-item label="探针" prop="probeRisk">
                            <el-input v-model="state.number.probeRisk" placeholder="请输入探针" clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </section>

        <section class="flex-align-center" v-if="isPlatform">
            <el-button type="primary" @click="platSure">保存</el-button>
        </section>
    </section>

</template>